/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models.DAOs;

/**
 *
 * @author 0905
 */

import DBConnection.ConnectionFactory;
import Models.Address;
import java.lang.Exception;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class Address_DAO {
    
    
    public boolean addAddress(Address address,int customerID){
        try{
            
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO address(houseNo, street, subdivision, postalCode, country, type, customerID) VALUES (?,?,?,?,?)");
            
            pstmt.setInt(i++, address.getAddressID());
            pstmt.setString(i++, address.getStreet());
            pstmt.setString(i++, address.getSubdivision());
            pstmt.setString(i++, address.getPostalCode());
            pstmt.setString(i++, address.getCountry());
            pstmt.setInt(i++, address.isType());
            pstmt.setInt(i++,customerID);

            pstmt.executeUpdate();
            
            return true;
        }
        catch(SQLException e){
            e.printStackTrace();
            return false;
        }
    }
    
    public boolean updateAddress(Address address){
        try{
            
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1;
            PreparedStatement pstmt = conn.prepareStatement("UPDATE address SET addressID = ?, street = ?, subdivision = ?, postalCode = ?, country = ?, type = ?");
            
            pstmt.setInt(i, address.getAddressID());
            pstmt.setString(i, address.getStreet());
            pstmt.setString(i, address.getSubdivision());
            pstmt.setString(i, address.getPostalCode());
            pstmt.setString(i, address.getCountry());
            pstmt.setInt(i, address.isType());

            pstmt.executeUpdate();
            
                     
            return true;
        }
        catch(SQLException e){
            e.printStackTrace();
            return false;
        }
    }
    
    
    
    
}
